package example.title.com.ontouchtest

import android.content.Context
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.banner_item_app.view.*
import pagerbanner.library.com.OnBannerListener
import pagerbanner.library.com.PagerBannerView

class MainActivity : AppCompatActivity() {

    private val data=ArrayList<BannerItem>()
    lateinit var pbv_test:PagerBannerView<BannerItem>
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        iv_t.setImageResource(R.drawable.test_1)
        val item1= BannerItem()
        item1.resId=R.drawable.test_1
        item1.title="one"
        val item2= BannerItem()
        item2.resId=R.drawable.test_2
        item2.title="two"
        val item3= BannerItem()
        item3.resId=R.drawable.test_3
        item3.title="three"
        data.add(item1)
        data.add(item2)
        data.add(item3)
        pbv_test=PagerBannerView<BannerItem>(this)
        val params=LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT)
        pbv_test.layoutParams=params
        linear_vp_body.addView(pbv_test)
        pbv_test.setOnBannerListener(object :OnBannerListener<BannerItem>{
            override fun onBannerView(context: Context?, item: BannerItem?, position: Int): View {
                val view=LayoutInflater.from(context).inflate(R.layout.banner_item_app,null)
                view.iv_item.setImageResource(item!!.resId)
                return view
            }

            override fun onBannerItemClick(item: BannerItem?, position: Int) {
                Toast.makeText(this@MainActivity,"$position",Toast.LENGTH_SHORT).show()
            }

        })
        pbv_test.setBannerItems(data)
        pbv_test.start()
        pbv_test.pageMargin=-70
    }

    override fun onResume() {
        super.onResume()
        pbv_test.start()
    }

    override fun onPause() {
        super.onPause()
        pbv_test.stop()
    }

}
